<extend name="./public/frame.html"/>
<block name="content">
    <div class="layui-inline">
        <select lay-verify="required" class="layui-input" style="width:150px;" lay-search="" id="type">
            <option value="1">发现日期</option>
            <option value="2">处理时间</option>
        </select>
    </div>
    <div class="layui-inline">
        <input type="text" class="layui-input date" readonly id="start" placeholder="开始时间">
    </div>
    <div class="layui-inline">
        <input type="text" class="layui-input date" readonly id="end" placeholder="结束时间">
    </div>
    <div class="layui-inline">
        <select lay-verify="required" lay-search="" class="layui-input" style="width: 150px;" id="dispose">
            <option value="">是否领取</option>
            <option value="1">是</option>
            <option value="2">否</option>
        </select>
    </div>
    <div class="layui-inline">
        <select lay-verify="required" lay-search="" class="layui-input" style="width: 150px;" id="category">
            <option value="">物品种类</option>
            <volist name="lost_goods_type" id="type">
                <option value="{$key}">{$type}</option>
            </volist>
        </select>
    </div>
    <div class="layui-inline">
        <input type="text" placeholder="司机姓名" class="layui-input" id="driver_name">
    </div>
    <div class="layui-inline">
        <input type="text" required placeholder="司机电话" class="layui-input" id="driver_phone">
    </div>
    <div class="layui-inline">
        <button class="layui-btn" data-type="search">搜索</button>
        <button class="layui-btn layui-btn-disabled" data-type="" id="reset">复位</button>
    </div>
    <table class="layui-table"
           lay-data="{ height:'auto', url:'{:url('driver_service/tableLost')}', page: true, limit: '10', id:'lost'}"
           lay-filter="lost">
        <thead>
        <tr>
            <th lay-data="{checkbox:true, fixed: true}"></th>
            <th lay-data="{field:'lost_id', width:80, fixed: true, sort: true}">ID</th>
            <th lay-data="{field:'driver_name', width:120}">司机姓名</th>
            <th lay-data="{field:'driver_phone', width:120}">司机电话</th>
            <th lay-data="{field:'lost_goods_type', width:120}">物品类型</th>
            <th lay-data="{field:'found_at', width:140, sort: true}">发现日期</th>
            <th lay-data="{field:'is_dispose', width:120, templet:'#disposeTpl'}">是否领取</th>
            <th lay-data="{field:'owner_lost', width:120}">失主</th>
            <th lay-data="{field:'handle_time', width:140}">处理时间</th>
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:180, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
        {{#if(d.is_dispose==1){ }}
        <a class="layui-btn layui-btn-xs layui-btn-disabled">编辑</a>
        {{#}else{ }}
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>
        {{#} }}
    </script>
    <script type="text/html" id="disposeTpl">
        {{#if(d.is_dispose==2){}}
        否
        {{#}else{}}
        是
        {{#}}}
    </script>

    <script type="application/javascript">
        layui.use(['table', 'form', 'laydate', 'layer'], function () {
            var table = layui.table
                , form = layui.form
                , layer = layui.layer
                , laydate = layui.laydate;
            lay('.date').each(function () {
                laydate.render({elem: this, type: 'date', trigger: 'click'});
            });

            //监听工具条
            table.on('tool(lost)', function (obj) {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                var lost_id = data.lost_id;
                if (layEvent === 'detail') {
                    layer.open({
                        type: 2,
                        title: '乘客物品遗失详情',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/driver_service/lostDetail","lost_id=")}' + lost_id //iframe的url
                    });
                }
                else if (layEvent === 'edit') {
                    layer.open({
                        type: 2,
                        title: '乘客物品遗失详情编辑',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/driver_service/lostRegister","lost_id=")}' + lost_id, //iframe的url
                        cancel: function (index, layero) {
                            table.reload('lost', "{:url('/admin/driver_service/tableLost')}");
                        }
                    });
                }
            });

            var $ = layui.jquery, active = {
                search: function () {
                    var type = $('#type').val();
                    var start = $('#start').val();
                    var end = $('#end').val();
                    var category = $('#category').val();
                    var dispose = $('#dispose').val();
                    var driver_name = $.trim($('#driver_name').val());
                    var driver_phone = $.trim($('#driver_phone').val());
                    var reset = $('#reset');
                    if (start || end || category || dispose || driver_name || driver_phone) {
                        reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
                        table.reload('lost', {
                            url: '/admin/driver_service/lostSearch',
                            where: {
                                type: type,
                                start: start,
                                end: end,
                                category: category,
                                driver_name: driver_name,
                                driver_phone: driver_phone,
                                dispose: dispose
                            } //设定异步数据接口的额外参数
                        });
                    } else {
                        reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                        alert('搜索项不能为空');
                    }
                }
                , reset: function () {
                    var reset = $('#reset');
                    if (reset.data('type') !== '') {
                        table.reload('lost', {
                            url: '/admin/driver_service/tableLost', where: {}
                        });
                    }
                    $('.layui-input').each(function () {                        $(this).val('');                    });                $('.layui-this').each(function () {$(this).removeClass('layui-this');});
                    reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                }
            };

            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
</block>
